﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TGB.Core.Infrastructure;
using TGBTech.Core.Models.Models.BaoCao.SoChiTietThanhToanKHModel;
using PagedList;
using TGBTech.Core.Models.Services;

namespace TGBTech.WebAdmin.Controllers
{
    public class SoCTCongNoKHController : Controller
    {
        

        //session variable
        public static String SESSION_SCTTTKH_STARTDATE = "session_sctttkh_startdate";
        public static String SESSION_SCTTTKH_ENDDATE = "session_sctttkh_enddate";
        public static String SESSION_SCTTTKH_LIST = "session_sctttkh_list";

        //record per page 
        public static int RecordPerNumber = 100;

        private TGBTechDb db = new TGBTechDb();

        //
        // GET: /SoCTCongNoKH/
        public ActionResult Index()
        {
            return View();
        }
        //
        // GET: /SoChiTietThanhToanKH/Create
        public ActionResult Create(int? page)
        {
            //init page number
            int pageNumber = (page ?? 1);
            //get list from session
            var list = Session[SESSION_SCTTTKH_LIST] as List<SoChiTietThanhToanKHModel>;
            //check list with null value
            if (list == null)
            {
                list = new List<SoChiTietThanhToanKHModel>();
            }
            //return to view pagelist 
            return View(list.ToPagedList(pageNumber, RecordPerNumber));
        }

        //
        // POST: /SoChiTietThanhToanKH/Create
        [HttpPost]
        public ActionResult Create(DateTime StartDate, DateTime EndDate, int? page, String matk, String makh)
        {
            // TODO: Add insert logic here
            //Goi services
            int pageNumber = (page ?? 1);
            SoChiTietThanhToanKHService service = new SoChiTietThanhToanKHService();

            var list = service.createSoChiTietThanhToanKH(makh, matk, StartDate, EndDate).ListModel
                .AsQueryable().OrderBy(p => p.NgayThangCT).ToList();
            Session[SESSION_SCTTTKH_LIST] = list;
            return View("Create", list.ToPagedList(pageNumber, RecordPerNumber));
        }

	}
}